/**
 *	canvas에 그림 그리기 
 */

var start=false;
var startX=0, startY=0;
var ctx;
function drawingInit(){
	
	document.getElementById('canvas').onmousemove=c;
	document.getElementById('canvas').onmouseup=set;
	ctx = document.getElementById('canvas').getContext('2d');
}
function set(e){
	var lc;
	var lw;
	start = !start;//클릭하면 참 과 거짓 교차
	startX=e.x-12;
	startY=e.y-12;
	//선그리기 시작점 설정
	if(start){
		ctx.beginPath();
		ctx.moveTo(startX,startY);
		lc = document.getElementById('lineColor');
		lw = document.getElementById("lineWidth");
		ctx.strokeStyle=lc.value;
		ctx.lineWidth = lw.value;
	}
	else{
		ctx.closePath();
	}
}
function c(event){
	
	var d = document.getElementById("result");
	var x = event.x;
	var y = event.y;
	d.innerHTML = 'x=' + x + ',y=' + y;
	if (start) {
		ctx.lineTo(x, y);
		ctx.stroke();
	}
}